﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;

namespace OnlineEducation.Data.Entities
{
    // Add profile data for application users by adding properties to the ApplicationUser class
    public class ApplicationUser : IdentityUser<int>
    {
        /// <summary>
        /// 用户
        /// </summary>
        [StringLength(100)]
        [Display(Name = "姓名")]
        public string FullName { get; set; }

        [Display(Name = "性别")]
        public int? Gender { get; set; }

        [Display(Name = "生日")]
        public DateTime? BirthDate { get; set; }

        [StringLength(100)]
        [Display(Name = "微信")]
        public string WeChat { get; set; }

        [StringLength(100)]
        [Display(Name = "微博")]
        public string Weibo { get; set; }

        [StringLength(100)]
        [Display(Name = "QQ")]
        public string QQ { get; set; }


        [StringLength(200)]
        [Display(Name = "头衔")]
        public string Title { get; set; }
        [StringLength(200)]
        [Display(Name = "个性签名")]
        public string Signature { get; set; }
        [StringLength(200)]
        [Display(Name = "头像")]
        public string avatar { get; set; }
        [StringLength(500)]
        [Display(Name = "个人简介")]
        public string Intro { get; set; }

        [StringLength(500)]
        [Display(Name = "地址")]
        public string Address { get; set; }

     
        [StringLength(500)]
        [Display(Name = "备注")]
        public string Remark { get; set; }

        /// <summary>
        /// 建立时间
        /// </summary>
        [Display(Name = "建立时间")]
        public DateTime CreatedTime { get; set; }

        [Display(Name = "状态")]
        public bool Status
        {
            get
            {
                return !(this.LockoutEnabled && this.LockoutEnd.HasValue && this.LockoutEnd.Value > DateTime.UtcNow);
            }
        }

        public List<Booking> CourseBookings { get; set; }//For student user

        public List<TeachingPlan> TeachingPlans { get; set; }//For teacher user

        [InverseProperty("User")]
        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }

    }



    public class ApplicationRole : IdentityRole<int>
    {
        [InverseProperty("Role")]
        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }

        public ApplicationRole() : base()
        {

        }
        public ApplicationRole(string name) : base(name)
        {

        }
    }
    public class ApplicationUserRole : IdentityUserRole<int>
    {
        [ForeignKey("User")]
        public override int UserId { get => base.UserId; set => base.UserId = value; }

        [ForeignKey("Role")]
        public override int RoleId { get => base.RoleId; set => base.RoleId = value; }

        public virtual ApplicationUser User { get; set; }
        public virtual ApplicationRole Role { get; set; }


    }
}